from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-02 14:11:02.607599
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 02, Nov, 2022
Time: 14:11:11
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8751
Nobs: 828.000 HQIC: -51.1913
Log likelihood: 10790.7 FPE: 4.81347e-23
AIC: -51.3880 Det(Omega_mle): 4.32051e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.291486 0.051279 5.684 0.000
L1.Burgenland 0.108947 0.035011 3.112 0.002
L1.Kärnten -0.106671 0.018645 -5.721 0.000
L1.Niederösterreich 0.210924 0.073248 2.880 0.004
L1.Oberösterreich 0.102473 0.069970 1.465 0.143
L1.Salzburg 0.249870 0.037217 6.714 0.000
L1.Steiermark 0.036521 0.048743 0.749 0.454
L1.Tirol 0.107239 0.039534 2.713 0.007
L1.Vorarlberg -0.057836 0.034038 -1.699 0.089
L1.Wien 0.061304 0.062637 0.979 0.328
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063067 0.105981 0.595 0.552
L1.Burgenland -0.032065 0.072358 -0.443 0.658
L1.Kärnten 0.047143 0.038533 1.223 0.221
L1.Niederösterreich -0.171594 0.151384 -1.133 0.257
L1.Oberösterreich 0.379595 0.144610 2.625 0.009
L1.Salzburg 0.287335 0.076918 3.736 0.000
L1.Steiermark 0.106394 0.100738 1.056 0.291
L1.Tirol 0.316190 0.081706 3.870 0.000
L1.Vorarlberg 0.024654 0.070347 0.350 0.726
L1.Wien -0.014146 0.129454 -0.109 0.913
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188372 0.026371 7.143 0.000
L1.Burgenland 0.091204 0.018004 5.066 0.000
L1.Kärnten -0.008823 0.009588 -0.920 0.357
L1.Niederösterreich 0.265380 0.037668 7.045 0.000
L1.Oberösterreich 0.122045 0.035983 3.392 0.001
L1.Salzburg 0.049240 0.019139 2.573 0.010
L1.Steiermark 0.018037 0.025066 0.720 0.472
L1.Tirol 0.096217 0.020330 4.733 0.000
L1.Vorarlberg 0.058859 0.017504 3.363 0.001
L1.Wien 0.120386 0.032212 3.737 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.102394 0.027124 3.775 0.000
L1.Burgenland 0.045954 0.018519 2.482 0.013
L1.Kärnten -0.017050 0.009862 -1.729 0.084
L1.Niederösterreich 0.195002 0.038744 5.033 0.000
L1.Oberösterreich 0.286562 0.037011 7.743 0.000
L1.Salzburg 0.117817 0.019686 5.985 0.000
L1.Steiermark 0.102650 0.025782 3.981 0.000
L1.Tirol 0.120480 0.020911 5.762 0.000
L1.Vorarlberg 0.070704 0.018004 3.927 0.000
L1.Wien -0.025264 0.033132 -0.763 0.446
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118860 0.049129 2.419 0.016
L1.Burgenland -0.049699 0.033543 -1.482 0.138
L1.Kärnten -0.040595 0.017863 -2.273 0.023
L1.Niederösterreich 0.169055 0.070177 2.409 0.016
L1.Oberösterreich 0.137910 0.067037 2.057 0.040
L1.Salzburg 0.284816 0.035657 7.988 0.000
L1.Steiermark 0.034465 0.046699 0.738 0.461
L1.Tirol 0.166883 0.037876 4.406 0.000
L1.Vorarlberg 0.106143 0.032611 3.255 0.001
L1.Wien 0.073786 0.060011 1.230 0.219
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054055 0.038904 1.389 0.165
L1.Burgenland 0.040407 0.026561 1.521 0.128
L1.Kärnten 0.049774 0.014145 3.519 0.000
L1.Niederösterreich 0.225974 0.055571 4.066 0.000
L1.Oberösterreich 0.278736 0.053084 5.251 0.000
L1.Salzburg 0.054224 0.028235 1.920 0.055
L1.Steiermark -0.007190 0.036979 -0.194 0.846
L1.Tirol 0.153439 0.029993 5.116 0.000
L1.Vorarlberg 0.070711 0.025823 2.738 0.006
L1.Wien 0.080536 0.047520 1.695 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169463 0.046480 3.646 0.000
L1.Burgenland -0.005083 0.031734 -0.160 0.873
L1.Kärnten -0.061515 0.016900 -3.640 0.000
L1.Niederösterreich -0.083440 0.066392 -1.257 0.209
L1.Oberösterreich 0.193384 0.063422 3.049 0.002
L1.Salzburg 0.058266 0.033734 1.727 0.084
L1.Steiermark 0.228955 0.044181 5.182 0.000
L1.Tirol 0.496389 0.035834 13.853 0.000
L1.Vorarlberg 0.050872 0.030852 1.649 0.099
L1.Wien -0.045581 0.056775 -0.803 0.422
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150593 0.053217 2.830 0.005
L1.Burgenland -0.010376 0.036333 -0.286 0.775
L1.Kärnten 0.065032 0.019349 3.361 0.001
L1.Niederösterreich 0.201105 0.076016 2.646 0.008
L1.Oberösterreich -0.063791 0.072614 -0.878 0.380
L1.Salzburg 0.219633 0.038624 5.686 0.000
L1.Steiermark 0.115895 0.050584 2.291 0.022
L1.Tirol 0.081367 0.041027 1.983 0.047
L1.Vorarlberg 0.125091 0.035324 3.541 0.000
L1.Wien 0.116960 0.065004 1.799 0.072
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348357 0.031077 11.209 0.000
L1.Burgenland 0.006869 0.021218 0.324 0.746
L1.Kärnten -0.024159 0.011299 -2.138 0.033
L1.Niederösterreich 0.224731 0.044391 5.063 0.000
L1.Oberösterreich 0.171053 0.042404 4.034 0.000
L1.Salzburg 0.049097 0.022555 2.177 0.029
L1.Steiermark -0.015053 0.029540 -0.510 0.610
L1.Tirol 0.111678 0.023959 4.661 0.000
L1.Vorarlberg 0.073969 0.020628 3.586 0.000
L1.Wien 0.054381 0.037960 1.433 0.152
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041893 0.154262 0.189761 0.161299 0.126878 0.117911 0.066772 0.228435
Kärnten 0.041893 1.000000 -0.001389 0.130804 0.042528 0.097228 0.428160 -0.052244 0.101866
Niederösterreich 0.154262 -0.001389 1.000000 0.340065 0.158854 0.303952 0.115956 0.185972 0.332328
Oberösterreich 0.189761 0.130804 0.340065 1.000000 0.234376 0.335441 0.175079 0.176612 0.267488
Salzburg 0.161299 0.042528 0.158854 0.234376 1.000000 0.149681 0.134512 0.150253 0.139321
Steiermark 0.126878 0.097228 0.303952 0.335441 0.149681 1.000000 0.157714 0.144054 0.084081
Tirol 0.117911 0.428160 0.115956 0.175079 0.134512 0.157714 1.000000 0.117156 0.159671
Vorarlberg 0.066772 -0.052244 0.185972 0.176612 0.150253 0.144054 0.117156 1.000000 0.010755
Wien 0.228435 0.101866 0.332328 0.267488 0.139321 0.084081 0.159671 0.010755 1.000000